/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmClinic.java
 * Auther Marcel Belisle
 * Created on Apr 6, 2011, 11:43:51 AM
 */

package khmhappointmentsystem;

import java.sql.PreparedStatement;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author mbelisle
 */
public class FrmClinic extends javax.swing.JInternalFrame {

    /** Creates new form FrmClinic */
    public FrmClinic() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblname = new javax.swing.JLabel();
        txtname = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtspecialist = new javax.swing.JTextField();
        cmdcancel = new javax.swing.JButton();
        cmdsave = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtLimit = new javax.swing.JTextField();

        setClosable(true);
        setIconifiable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(FrmClinic.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        lblname.setText(resourceMap.getString("lblname.text")); // NOI18N
        lblname.setName("lblname"); // NOI18N

        txtname.setText(resourceMap.getString("txtname.text")); // NOI18N
        txtname.setName("txtname"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtspecialist.setText(resourceMap.getString("txtspecialist.text")); // NOI18N
        txtspecialist.setName("txtspecialist"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(FrmClinic.class, this);
        cmdcancel.setAction(actionMap.get("cancel")); // NOI18N
        cmdcancel.setIcon(resourceMap.getIcon("cmdcancel.icon")); // NOI18N
        cmdcancel.setText(resourceMap.getString("cmdcancel.text")); // NOI18N
        cmdcancel.setName("cmdcancel"); // NOI18N

        cmdsave.setAction(actionMap.get("save")); // NOI18N
        cmdsave.setIcon(resourceMap.getIcon("cmdsave.icon")); // NOI18N
        cmdsave.setText(resourceMap.getString("cmdsave.text")); // NOI18N
        cmdsave.setName("cmdsave"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txtLimit.setText(resourceMap.getString("txtLimit.text")); // NOI18N
        txtLimit.setName("txtLimit"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblname)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtspecialist, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                                    .addComponent(txtname, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                                    .addComponent(txtLimit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cmdsave)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cmdcancel, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(27, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addContainerGap(216, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblname)
                    .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtspecialist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtLimit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdcancel)
                    .addComponent(cmdsave))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-288)/2, (screenSize.height-165)/2, 288, 165);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void cancel() {
        this.dispose();
    }

    @Action
    public void save() {

        String name = txtname.getText();
        String specialist = txtspecialist.getText();
        String limit = txtLimit.getText().trim();

        try{
            String query = "Insert into clinic (name,specialist,limit)values(?,?,?)";
            PreparedStatement pstmt =Environment.getDbConn().prepareStatement(query);
            pstmt.setString(1, name);
            pstmt.setString(2, specialist);
            pstmt.setString(3, limit);
            pstmt.executeUpdate();
            JOptionPane.showMessageDialog(rootPane, "Clinic Successfully Created.");

            //Clear textboxes
            txtname.setText("");
            txtspecialist.setText("");
            txtLimit.setText("");
        }
        catch(Exception e){
            System.out.println("Unable to save new Clinic.");
            e.printStackTrace();
        }

    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdcancel;
    private javax.swing.JButton cmdsave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel lblname;
    private javax.swing.JTextField txtLimit;
    private javax.swing.JTextField txtname;
    private javax.swing.JTextField txtspecialist;
    // End of variables declaration//GEN-END:variables

}
